// 生成大量模拟充电站数据的脚本
import { writeFileSync } from 'fs';

// 基础数据模板
const baseStations = [
  {
    "address": "犀浦镇国宁东路69号百伦广场犀浦店地下停车场258",
    "brandName": "依威",
    "brandType": 1,
    "distance": 1859.03,
    "electricityPrice": 1.20,
    "lat": 30.756089,
    "lng": 103.975038,
    "openStatus": 1,
    "openTime": "00:00-24:00",
    "operatorId": "320513112",
    "parkCost": 2,
    "parkFee": "全天开放",
    "quickAvailableNum": 0,
    "quickChargeNum": 0,
    "servicePrice": 0.80,
    "slowAvailableNum": 10,
    "slowChargeNum": 10,
    "stationCategory": [64],
    "stationGradeScore": 0.0,
    "stationId": "28-093",
    "stationLevel": 0,
    "stationName": "百伦广场犀浦店停车场",
    "stationStatus": 50,
    "stationTel": "13811111111",
    "totalCostPrice": 2.00
  },
  {
    "address": "百草路1067号天府创意产业园地面停车场",
    "brandName": "依威",
    "brandType": 1,
    "distance": 2464.3,
    "electricityPrice": 1.20,
    "lat": 30.751367,
    "lng": 103.953172,
    "openStatus": 1,
    "openTime": "00:00-24:00",
    "operatorId": "320513112",
    "parkCost": 2,
    "parkFee": "全天开放",
    "quickAvailableNum": 0,
    "quickChargeNum": 0,
    "servicePrice": 0.80,
    "slowAvailableNum": 6,
    "slowChargeNum": 6,
    "stationCategory": [],
    "stationGradeScore": 0.0,
    "stationId": "28-231",
    "stationLevel": 1,
    "stationName": "天府创业园",
    "stationStatus": 50,
    "stationTel": "13811111111",
    "totalCostPrice": 2.00
  }
];

// 品牌名称列表
const brandNames = ['依威', '国家电网', '特来电', '星星充电', '小桔充电', '万马奔腾', '安悦充电', '云快充', '蔚景云', '特锐德'];

// 区域名称列表
const areaNames = ['高新区', '锦江区', '武侯区', '青羊区', '金牛区', '成华区', '郫都区', '双流区', '温江区', '龙泉驿区'];

// 场所类型列表
const placeTypes = ['购物中心', '写字楼', '酒店', '医院', '学校', '小区', '公园', '体育中心', '机场', '火车站'];

// 生成随机浮点数
function randomFloat(min, max, precision = 6) {
  return parseFloat((Math.random() * (max - min) + min).toFixed(precision));
}

// 生成随机整数
function randomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// 生成随机字符串ID
function generateStationId() {
  const prefixes = ['28-', '30-', '51-', '77-', '88-'];
  const prefix = prefixes[randomInt(0, prefixes.length - 1)];
  const suffix = String(randomInt(100, 9999)).padStart(4, '0');
  return prefix + suffix;
}

// 生成随机地址
function generateAddress(baseLat, baseLng, index) {
  const area = areaNames[randomInt(0, areaNames.length - 1)];
  const place = placeTypes[randomInt(0, placeTypes.length - 1)];
  const streetNumber = randomInt(1, 9999);
  return `${area}${place}附近${streetNumber}号`;
}

// 生成大量模拟数据
function generateMockData(count = 100) {
  const stationList = [];
  
  // 基于现有站点扩展，保持在成都犀浦区域附近
  const baseLat = 30.75;
  const baseLng = 103.97;
  
  for (let i = 0; i < count; i++) {
    // 随机偏移量，保持在一定地理范围内
    const latOffset = randomFloat(-0.05, 0.05);
    const lngOffset = randomFloat(-0.05, 0.05);
    
    // 随机选择品牌
    const brandName = brandNames[randomInt(0, brandNames.length - 1)];
    
    // 随机生成充电桩数量和可用数量
    const quickChargeNum = randomInt(0, 10);
    const slowChargeNum = randomInt(0, 20);
    const quickAvailableNum = Math.min(randomInt(0, quickChargeNum + 2), quickChargeNum);
    const slowAvailableNum = Math.min(randomInt(0, slowChargeNum + 3), slowChargeNum);
    
    // 随机价格
    const electricityPrice = randomFloat(0.8, 1.5, 2);
    const servicePrice = randomFloat(0.5, 1.2, 2);
    const totalCostPrice = parseFloat((electricityPrice + servicePrice).toFixed(2));
    
    // 生成站点数据
    const station = {
      "address": generateAddress(baseLat + latOffset, baseLng + lngOffset, i),
      "brandName": brandName,
      "brandType": randomInt(1, 5),
      "distance": randomFloat(100, 10000, 2),
      "electricityPrice": electricityPrice,
      "lat": parseFloat((baseLat + latOffset).toFixed(6)),
      "lng": parseFloat((baseLng + lngOffset).toFixed(6)),
      "openStatus": randomInt(0, 1),
      "openTime": randomInt(0, 1) ? "00:00-24:00" : `${String(randomInt(6, 8)).padStart(2, '0')}:00-${String(randomInt(20, 22)).padStart(2, '0')}:00`,
      "operatorId": String(randomInt(100000000, 999999999)),
      "parkCost": randomInt(0, 10),
      "parkFee": randomInt(0, 1) ? "全天开放" : `${randomInt(0, 2)}小时内免费，超出${randomInt(2, 10)}元/小时`,
      "quickAvailableNum": quickAvailableNum,
      "quickChargeNum": quickChargeNum,
      "servicePrice": servicePrice,
      "slowAvailableNum": slowAvailableNum,
      "slowChargeNum": slowChargeNum,
      "stationCategory": randomInt(0, 1) ? [randomInt(1, 100)] : [],
      "stationGradeScore": randomFloat(0, 5, 1),
      "stationId": generateStationId(),
      "stationLevel": randomInt(0, 3),
      "stationName": `${brandName}${areaNames[randomInt(0, areaNames.length - 1)]}${placeTypes[randomInt(0, placeTypes.length - 1)]}充电站`,
      "stationStatus": randomInt(0, 100),
      "stationTel": `13${String(randomInt(100000000, 999999999)).padStart(9, '0')}`,
      "totalCostPrice": totalCostPrice
    };
    
    stationList.push(station);
  }
  
  // 添加原始的两个站点到列表开头
  stationList.unshift(...baseStations);
  
  return {
    "pageIndex": 1,
    "pageSize": stationList.length,
    "stationList": stationList,
    "total": stationList.length,
    "totalPage": 1
  };
}

// 生成100个站点的数据
const mockData = generateMockData(100);

// 保存到文件
writeFileSync('./mockStations.json', JSON.stringify(mockData, null, 2), 'utf8');
console.log(`已生成 ${mockData.stationList.length} 个模拟充电站数据，保存到 mockStations.json`);
